//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#ifndef Green_PhysicalPageSplitter_H
#define Green_PhysicalPageSplitter_H

#include "Defines.h"

namespace Green {

  struct PhysicalPageSplit {
  public:
    uint64 mPa1; // Starting physical address for range intersecting with first page.
    uint32 mSize1; // Size of range intersecting with first page.
    uint32 mBank1; // Memory bank for first page.
    uint64 mPa2; // Starting physical address for range intersecting with second page.
    uint32 mSize2; // Size of range intersecting with second page.
    uint32 mBank2; // Memory bank for second page.
  };

  class VmMapper;
  class TranslationRange;

  /*!
    \class PhysicalPageSplitter
    \brief Class to split a VA range into one or more PA ranges, according to page boundaries.
  */
  class PhysicalPageSplitter {
  public:
    explicit PhysicalPageSplitter(const VmMapper* pVmMapper); //!< Constructor
    COPY_CONSTRUCTOR_ABSENT(PhysicalPageSplitter);
    DESTRUCTOR_DEFAULT(PhysicalPageSplitter); //!< Destructor
    ASSIGNMENT_OPERATOR_ABSENT(PhysicalPageSplitter);

    PhysicalPageSplit GetPhysicalPageSplit(cuint64 va, cuint32 size) const; //!< Get PA ranges corresponding to VA range.
  private:
    void GetTranslationRange(cuint64 va, TranslationRange& rTransRange) const; //!< Get translation range for the specified VA.
  private:
    const VmMapper* mpVmMapper;
  };

}

#endif  // Green_PhysicalPageSplitter_H
